package com.kaoshi.myweb.webtest.java.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class VehicleProxy implements InvocationHandler {
	private Object target;
	
	/**
	 * 绑定委托对象并返回一个代理类
	 * @param target
	 * @return
	 */
	public Object bind(Object target) {
		this.target = target;
		//取得代理对象  
		return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		
		System.out.println("you are going to invoke " + method.getName());
		//执行方法 
		Object object = method.invoke(target, args);
		System.out.println( method.getName() + "has been finshed ");
		return object;
	}

}
